Merge "mediawiki.js: Move mw.format definition to where it's exposed"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 13 Jan 2015 19:25:20 +0000 (19:25 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 13 Jan 2015 19:25:20 +0000 (19:25 +0000)
13 files changed:
autoload.php
includes/DeferredStringifier.php [deleted file]
includes/User.php
includes/changes/RecentChange.php
includes/diff/DifferenceEngine.php
includes/libs/DeferredStringifier.php [new file with mode: 0644]
includes/page/Article.php
includes/specials/SpecialUpload.php
includes/specials/SpecialUserrights.php
languages/i18n/en.json
languages/i18n/qqq.json
tests/phpunit/includes/UserTest.php
tests/phpunit/includes/libs/DeferredStringifierTest.php [new file with mode: 0644]

index 674d4b0..72345fe 100644 (file)
@@ -292,7 +292,7 @@ $wgAutoloadLocalClasses = array(
        'DateFormatter' => __DIR__ . '/includes/parser/DateFormatter.php',
        'DeadendPagesPage' => __DIR__ . '/includes/specials/SpecialDeadendpages.php',
        'DeferrableUpdate' => __DIR__ . '/includes/deferred/DeferredUpdates.php',
-       'DeferredStringifier' => __DIR__ . '/includes/DeferredStringifier.php',
+       'DeferredStringifier' => __DIR__ . '/includes/libs/DeferredStringifier.php',
        'DeferredUpdates' => __DIR__ . '/includes/deferred/DeferredUpdates.php',
        'DeleteAction' => __DIR__ . '/includes/actions/DeleteAction.php',
        'DeleteArchivedFiles' => __DIR__ . '/maintenance/deleteArchivedFiles.php',
diff --git a/includes/DeferredStringifier.php b/includes/DeferredStringifier.php
deleted file mode 100644 (file)
index bd32949..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-/**
- * Class that defers a slow string generation until the string is actually needed.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- */
-
-/**
- * @since 1.25
- */
-class DeferredStringifier {
-       /** @var callable Callback used for result string generation */
-       private $callback;
-       /** @var array */
-       private $params;
-       /** @var string */
-       private $result;
-
-       /**
-        * @param callable $callback Callback that gets called by __toString
-        * @param mixed $param,... Parameters to the callback
-        */
-       public function __construct( $callback /*...*/ ) {
-               $this->params = func_get_args();
-               array_shift( $this->params );
-               $this->callback = $callback;
-       }
-
-       /**
-        * Returns a string generated by callback
-        *
-        * @return string
-        */
-       public function __toString() {
-               if ( $this->result === null ) {
-                       $this->result = call_user_func_array( $this->callback, $this->params );
-               }
-               return $this->result;
-       }
-}
index 7ca7d80..ad4ce60 100644 (file)
@@ -4739,7 +4739,7 @@ class User implements IDBAccessObject {
                if ( $action === true ) {
                        $action = 'byemail';
                } elseif ( $action === false ) {
-                       if ( $this->getName() == $wgUser->getName() ) {
+                       if ( $this->equals( $wgUser ) ) {
                                $action = 'create';
                        } else {
                                $action = 'create2';
@@ -5024,4 +5024,15 @@ class User implements IDBAccessObject {
                        return Status::newFatal( 'badaccess-group0' );
                }
        }
+
+       /**
+        * Checks if two user objects point to the same user.
+        *
+        * @since 1.25
+        * @param User $user
+        * @return bool
+        */
+       public function equals( User $user ) {
+               return $this->getName() === $user->getName();
+       }
 }
index c719d8d..86cd1d7 100644 (file)
@@ -450,7 +450,7 @@ class RecentChange {
                }
                // Users without the 'autopatrol' right can't patrol their
                // own revisions
-               if ( $user->getName() == $this->getAttribute( 'rc_user_text' )
+               if ( $user->getName() === $this->getAttribute( 'rc_user_text' )
                        && !$user->isAllowed( 'autopatrol' )
                ) {
                        $errors[] = array( 'markedaspatrollederror-noautopatrol' );
index 90a2785..47967e4 100644 (file)
@@ -487,7 +487,7 @@ class DifferenceEngine extends ContextSource {
                                        array( 'USE INDEX' => 'rc_timestamp' )
                                );
 
-                               if ( $change && $change->getPerformer()->getName() !== $user->getName() ) {
+                               if ( $change && !$change->getPerformer()->equals( $user ) ) {
                                        $rcid = $change->getAttribute( 'rc_id' );
                                } else {
                                        // None found or the page has been created by the current user.
diff --git a/includes/libs/DeferredStringifier.php b/includes/libs/DeferredStringifier.php
new file mode 100644 (file)
index 0000000..bd32949
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Class that defers a slow string generation until the string is actually needed.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @since 1.25
+ */
+class DeferredStringifier {
+       /** @var callable Callback used for result string generation */
+       private $callback;
+       /** @var array */
+       private $params;
+       /** @var string */
+       private $result;
+
+       /**
+        * @param callable $callback Callback that gets called by __toString
+        * @param mixed $param,... Parameters to the callback
+        */
+       public function __construct( $callback /*...*/ ) {
+               $this->params = func_get_args();
+               array_shift( $this->params );
+               $this->callback = $callback;
+       }
+
+       /**
+        * Returns a string generated by callback
+        *
+        * @return string
+        */
+       public function __toString() {
+               if ( $this->result === null ) {
+                       $this->result = call_user_func_array( $this->callback, $this->params );
+               }
+               return $this->result;
+       }
+}
index 438a17c..9ce3854 100644 (file)
@@ -1129,7 +1129,7 @@ class Article implements Page {
                        return false;
                }
 
-               if ( $rc->getPerformer()->getName() == $user->getName() ) {
+               if ( $rc->getPerformer()->equals( $user ) ) {
                        // Don't show a patrol link for own creations. If the user could
                        // patrol them, they already would be patrolled
                        return false;
index 2a5b7ad..8dc9bb6 100644 (file)
@@ -937,35 +937,31 @@ class UploadForm extends HTMLForm {
                $config = $this->getConfig();
 
                if ( $config->get( 'CheckFileExtensions' ) ) {
+                       $fileExtensions = array_unique( $config->get( 'FileExtensions' ) );
                        if ( $config->get( 'StrictFileExtensions' ) ) {
                                # Everything not permitted is banned
                                $extensionsList =
                                        '<div id="mw-upload-permitted">' .
-                                       $this->msg(
-                                               'upload-permitted',
-                                               $this->getContext()->getLanguage()->commaList(
-                                                       array_unique( $config->get( 'FileExtensions' ) )
-                                               )
-                                       )->parseAsBlock() .
+                                       $this->msg( 'upload-permitted' )
+                                               ->params( $this->getLanguage()->commaList( $fileExtensions ) )
+                                               ->numParams( count( $fileExtensions ) )
+                                               ->parseAsBlock() .
                                        "</div>\n";
                        } else {
                                # We have to list both preferred and prohibited
+                               $fileBlacklist = array_unique( $config->get( 'FileBlacklist' ) );
                                $extensionsList =
                                        '<div id="mw-upload-preferred">' .
-                                               $this->msg(
-                                                       'upload-preferred',
-                                                       $this->getContext()->getLanguage()->commaList(
-                                                               array_unique( $config->get( 'FileExtensions' ) )
-                                                       )
-                                               )->parseAsBlock() .
+                                               $this->msg( 'upload-preferred' )
+                                                       ->params( $this->getLanguage()->commaList( $fileExtensions ) )
+                                                       ->numParams( count( $fileExtensions ) )
+                                                       ->parseAsBlock() .
                                        "</div>\n" .
                                        '<div id="mw-upload-prohibited">' .
-                                               $this->msg(
-                                                       'upload-prohibited',
-                                                       $this->getContext()->getLanguage()->commaList(
-                                                               array_unique( $config->get( 'FileBlacklist' ) )
-                                                       )
-                                               )->parseAsBlock() .
+                                               $this->msg( 'upload-prohibited' )
+                                                       ->params( $this->getLanguage()->commaList( $fileBlacklist ) )
+                                                       ->numParams( count( $fileBlacklist ) )
+                                                       ->parseAsBlock() .
                                        "</div>\n";
                        }
                } else {
index 892ff5b..36a31bd 100644 (file)
@@ -106,7 +106,7 @@ class UserrightsPage extends SpecialPage {
                        }
                }
 
-               if ( User::getCanonicalName( $this->mTarget ) == $user->getName() ) {
+               if ( User::getCanonicalName( $this->mTarget ) === $user->getName() ) {
                        $this->isself = true;
                }
 
@@ -228,7 +228,7 @@ class UserrightsPage extends SpecialPage {
                global $wgAuth;
 
                // Validate input set...
-               $isself = ( $user->getName() == $this->getUser()->getName() );
+               $isself = $user->equals( $this->getUser() );
                $groups = $user->getGroups();
                $changeable = $this->changeableGroups();
                $addable = array_merge( $changeable['add'], $isself ? $changeable['add-self'] : array() );
index 3c86243..9e072b6 100644 (file)
        "upload-summary": "",
        "upload-recreate-warning": "<strong>Warning: A file by that name has been deleted or moved.</strong>\n\nThe deletion and move log for this page are provided here for convenience:",
        "uploadtext": "Use the form below to upload files.\nTo view or search previously uploaded files go to the [[Special:FileList|list of uploaded files]], (re)uploads are also logged in the [[Special:Log/upload|upload log]], deletions in the [[Special:Log/delete|deletion log]].\n\nTo include a file in a page, use a link in one of the following forms:\n* <strong><code><nowiki>[[</nowiki>{{ns:file}}<nowiki>:File.jpg]]</nowiki></code></strong> to use the full version of the file\n* <strong><code><nowiki>[[</nowiki>{{ns:file}}<nowiki>:File.png|200px|thumb|left|alt text]]</nowiki></code></strong> to use a 200 pixel wide rendition in a box in the left margin with \"alt text\" as description\n* <strong><code><nowiki>[[</nowiki>{{ns:media}}<nowiki>:File.ogg]]</nowiki></code></strong> for directly linking to the file without displaying the file",
-       "upload-permitted": "Permitted file types: $1.",
-       "upload-preferred": "Preferred file types: $1.",
-       "upload-prohibited": "Prohibited file types: $1.",
+       "upload-permitted": "Permitted file {{PLURAL:$2|type|types}}: $1.",
+       "upload-preferred": "Preferred file {{PLURAL:$2|type|types}}: $1.",
+       "upload-prohibited": "Prohibited file {{PLURAL:$2|type|types}}: $1.",
        "uploadfooter": "-",
        "upload-default-description": "-",
        "uploadlogpage": "Upload log",
index 504658e..14345bf 100644 (file)
        "upload-summary": "{{doc-specialpagesummary|upload}}",
        "upload-recreate-warning": "Used as warning in [[Special:Upload]].",
        "uploadtext": "{{doc-important|<code>thumb</code> and <code>left</code> are magic words. Leave them untranslated!}}\nText displayed when uploading a file using [[Special:Upload]].",
-       "upload-permitted": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileExtensions|$wgFileExtensions]]\nSee also:\n* {{msg-mw|Upload-preferred}}\n* {{msg-mw|Upload-prohibited}}",
-       "upload-preferred": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileExtensions|$wgFileExtensions]]\nSee also:\n* {{msg-mw|Upload-permitted}}\n* {{msg-mw|Upload-prohibited}}",
-       "upload-prohibited": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileBlacklist|$wgFileBlacklist]]\nSee also:\n* {{msg-mw|Upload-permitted}}\n* {{msg-mw|Upload-preferred}}",
+       "upload-permitted": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileExtensions|$wgFileExtensions]]\n* $2 - count of items in $1 - for use in plural\nSee also:\n* {{msg-mw|Upload-preferred}}\n* {{msg-mw|Upload-prohibited}}",
+       "upload-preferred": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileExtensions|$wgFileExtensions]]\n* $2 - count of items in $1 - for use in plural\nSee also:\n* {{msg-mw|Upload-permitted}}\n* {{msg-mw|Upload-prohibited}}",
+       "upload-prohibited": "Used in [[Special:Upload]]. Parameters:\n* $1 - list of file types, defined in the variable [[mw:Special:MyLanguage/Manual:$wgFileBlacklist|$wgFileBlacklist]]\n* $2 - count of items in $1 - for use in plural\nSee also:\n* {{msg-mw|Upload-permitted}}\n* {{msg-mw|Upload-preferred}}",
        "uploadfooter": "{{notranslate}}",
        "upload-default-description": "{{ignored}}Custom default upload description. The contents of this message be will inserted in the field \"Summary\" on [[Special:Upload]].",
        "uploadlogpage": "{{doc-logpage}}\n\nPage title of [[Special:Log/upload]].",
index 8cc2a8e..c3cb193 100644 (file)
@@ -355,4 +355,34 @@ class UserTest extends MediaWikiTestCase {
                                'false' => 'With / slash' ), 'With slash' ),
                );
        }
+
+       /**
+        * @covers User::equals
+        */
+       public function testEquals() {
+               $first = User::newFromName( 'EqualUser' );
+               $second = User::newFromName( 'EqualUser' );
+
+               $this->assertTrue( $first->equals( $first ) );
+               $this->assertTrue( $first->equals( $second ) );
+               $this->assertTrue( $second->equals( $first ) );
+
+               $third = User::newFromName( '0' );
+               $fourth = User::newFromName( '000' );
+
+               $this->assertFalse( $third->equals( $fourth ) );
+               $this->assertFalse( $fourth->equals( $third ) );
+
+               // Test users loaded from db with id
+               $user = User::newFromName( 'EqualUnitTestUser' );
+               if ( !$user->getId() ) {
+                       $user->addToDatabase();
+               }
+
+               $id = $user->getId();
+
+               $fifth = User::newFromId( $id );
+               $sixth = User::newFromName( 'EqualUnitTestUser' );
+               $this->assertTrue( $fifth->equals( $sixth ) );
+       }
 }
diff --git a/tests/phpunit/includes/libs/DeferredStringifierTest.php b/tests/phpunit/includes/libs/DeferredStringifierTest.php
new file mode 100644 (file)
index 0000000..9aaf113
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+class DeferredStringifierTest extends PHPUnit_Framework_TestCase {
+
+       /**
+        * @covers DeferredStringifier
+        * @dataProvider provideToString
+        */
+       public function testToString( $params, $expected ) {
+               $class = new ReflectionClass( 'DeferredStringifier' );
+               $ds = $class->newInstanceArgs( $params );
+               $this->assertEquals( $expected, (string)$ds );
+       }
+
+       public static function provideToString() {
+               return array(
+                       // No args
+                       array( array( function() {
+                               return 'foo';
+                       } ), 'foo' ),
+                       // Has args
+                       array( array( function( $i ) {
+                               return $i;
+                       }, 'bar' ), 'bar' ),
+               );
+       }
+
+       /**
+        * Verify that the callback is not called if
+        * it is never converted to a string
+        */
+       public function testCallbackNotCalled() {
+               $ds = new DeferredStringifier( function() {
+                       throw new Exception( 'This should not be reached!' );
+               } );
+               // No exception was thrown
+               $this->assertTrue( true );
+       }
+}